// Tags: Digital DP
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 20;
int x, y, cnt, s[N];
ll l, r, f[N][10];

ll solve(int step, int d, bool lim, bool lead) {
  if (!step) return 1;
  if (!lim && ~f[step][d]) return f[step][d];
  int maxx = lim ? s[step] : 9;
  ll res = 0;
  for (int i = 0; i <= maxx; ++i) {
    if (!lead) {
      if (!(d == x && i == y))
        res += solve(step - 1, i, lim && i == maxx, false);
    } else
      res += solve(step - 1, i, lim && i == maxx, !i);
  }
  return lim || lead ? res : f[step][d] = res;
}

inline ll solve(ll num) {
  memset(f, -1, sizeof(f));
  cnt = 0;
  while (num) s[++cnt] = num % 10, num /= 10;
  return solve(cnt, 0, true, true);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("none.in", "r", stdin);
  freopen("none.out", "w", stdout);
#endif
#endif

  scanf("%lld%lld%d%d", &l, &r, &x, &y);
  printf("%lld", solve(r) - solve(l - 1));
  return 0;
}